<template>
	<view class="main">
		<!-- <u-navbar :is-back="false" title="首页" :background="background" :border-bottom="false"></u-navbar> -->
		<view class="wrap">
			
			<u-swiper :list="list"></u-swiper>
		</view>
		<u-sticky offset-top="0" bg-color=" #111111;">
			<view class="tabs">
				<view class="tabw" v-for="item,index in tab" :key="index">
					<view :class="tabed==index?'taborder':'tab'" @click="tabeds(index)">
						{{item}}
					</view>
				</view>
			</view>
		</u-sticky>
		<block v-if="tabed==0">
			<swiper class="swipers" :current="currentIndex" :circular="true" previous-margin="80rpx" next-margin="80rpx"
				:interval="3000" :duration="1000" @change="swierChange">
				<swiper-item v-for="(shop,i) in shoplist" :key="i">
					<view>
						<view class="swipe">
							<image class="bg" src="../../../static/images/home_img_sp(1).png" mode=""></image>
						</view>
						<view class="top">
							<text class="title" >{{shop.title}}</text>
							<text class="num">
								{{shop.issue_num}}份
							</text>
						</view>
						<view class="shop">
							<image :src="shop.issuer_img" mode="aspectFit"></image>
							<text>{{shop.issuer_name}}</text>
						</view>
						<view class="moneys">
							<text>￥</text>{{shop.price}}
						</view>
						<image :src="shop.img" class="slide-image" :class="currentIndex === i?'active':''"></image>
						<view class="button" >
							<view class="start">
								<text v-if="shop.status==0" @click="buy(tabed,i,shop.id)">即将开售</text>
								<text class="time" v-if="shop.status==0" @click="buy(tabed,i,shop.id)" >{{formatTime(shop.start_sale_time,'MM-DD hh:mm')}}</text>
							<text class="time" style="position: absolute; left: 85rpx; top: 5rpx; color: #F3C860;" v-if="shop.status==1"@click="buy(tabed,i,shop.id)">抢购中</text>
							<text v-if="shop.status==2" style="margin-left: 100rpx;color: #999999;" @click="buy(tabed,i,shop.id)">已售罄</text>
							<text v-if="shop.status==3" style="margin-left: 100rpx;color: #fff;" @click="buy(tabed,i,shop.id)">未上架</text>
							</view>
							<image style="width: 364rpx; height: 96rpx;"
								src="../../../static/images/home_icon_button.png" mode="" v-if="shop.status==0"></image>
								<image style="width: 364rpx; height: 96rpx;"
									src="../../../static/images/index2.png" mode="" v-if="shop.status==1"></image>
									<image style="width: 364rpx; height: 96rpx;"
										src="../../../static/images/index3.png" mode="" v-if="shop.status==2"></image>
										<image style="width: 364rpx; height: 96rpx;"
											src="../../../static/images/index3.png" mode="" v-if="shop.status==3"></image>
						</view>
						<view class="other">
							<view>
								分享
							</view>
							<view>
								查看
							</view>
						</view>
						<!-- 纯透明按钮 -->
						<view class="other2">
							<view>
								分享
							</view>
							<view @click="router('../box_details/box_details',tabed,shop.id)">
								查看
							</view>
						</view>
					</view>
				</swiper-item>
			</swiper>


		</block>
		<block v-if="tabed==1">
			<view class="seconds" v-for="shop2,index in shoplist" :key="index"
				@click="router('../blind_details/blind_details',tabed,shop2.id)">
				<view class="translate">
					<view class="tr_img">
						<image :src="shop2.img" mode=""></image>
					</view>
					<view class="tt_tit">
						{{shop2.title}}
					</view>
					<view class="count">
						<text class="coun_name">限量</text>
						<text class="coun_num">{{shop2.issue_num}}份</text>
					</view>
					<view class="sec_bot">
						<view class="market">
							<image :src="shop2.issuer_img" mode="aspectFit"></image>
							<text>{{shop2.issuer_name}}</text>
						</view>
						<view class="sec_moneys">
							<text>￥</text>{{shop2.price}}
						</view>
					</view>
				</view>
			</view>
		</block>
		<block v-if="tabed==2">
			<view class="seconds" v-for="shop3,index in shoplist" :key="index"
				@click="router('../sale_details/sale_details',tabed,shop3.id)">
				<view class="endtime" v-if="shop3.status==0">
					即将开售
					<text>{{formatTime(shop3.start_sale_time,'MM-DD hh:mm')}}</text>
				</view>
				<view class="endtime" v-if="shop3.status==1">
					售卖中
				</view>
				<view class="endtime" v-if="shop3.status==2">
					已结束
				</view>
				<view class="translate">
					<view class="tr_img">
						<image :src="shop3.img" mode=""></image>
					</view>
					<view class="tt_tit">
						{{shop3.title}}
					</view>
					<view class="count">
						<text class="coun_name">限量</text>
						<text class="coun_num">{{shop3.issue_num}}份</text>
					</view>
					<view class="sec_bot">
						<view class="market">
							<image :src="shop3.issuer_img" mode="aspectFit"></image>
							<text>{{shop3.issuer_name}}</text>
						</view>
						<view class="sec_moneys">
							<text>￥</text>{{shop3.price}}
						</view>
					</view>
				</view>
			</view>
		</block>
		<!-- <u-loading :show="show" style="margin-top: 100rpx;"></u-loading> -->
	</view>
</template>
<script>
	export default {
		data() {
			return {
				tab: ['数字藏品', '精彩盲盒', '预售抽签'],
				tabed: '', //1为普通商品 2为盲盒 3抽签
				currentIndex: 0,
				list: [{
					image:'',
					title:'',
				}],
				shoplist: [],
				num: 0,
			}
		},
		onShow() {

		},
		onLoad(options) {
			this.tabeds(0)
			this.getbanner()
			
		},

		methods: {
			//banner
			getbanner() {
				global.$http.request({
					url: '/api/home/banner',
					data: {}
				}).then(res => {
					if (res.data.code == 0) {
						for(var i=0;res.data.data.list.length;i++){
							this.list[i].image=res.data.data.list[i].img
							this.list[i].title=res.data.data.list[i].title
						}
					}
				})
			},
			getshoplist() {

			},
			swierChange(e) {
				this.currentIndex = e.detail.current
			},
			tabeds(type) {
				console.log(type);
				this.tabed = type
				global.$http.request({
					url: '/api/home/goodsList',
					data: {
						limit: 10,
						page: 1,
						category: type + 1,
					}
				}).then(res => {
					if (res.data.code == 0) {
						console.log(res.data.data.list);
						this.shoplist = res.data.data.list
					}
				})
			},
			router(path, type, id) {
				console.log(id);
				uni.navigateTo({
					url: path,
					success: function(res) {
						console.log(type + 1);
						console.log(id);
						res.eventChannel.emit('details', {
							data: {
								type: type + 1,
								id: id,
							}
						})
					}
				})
			},
			buy(tabid, index, b_id) {
				if(uni.getStorageSync('token')==''){
					uni.showToast({
						title: '请先登录',
						icon: "none",
						mask: true,
						duration: 2000
					})
					setTimeout(function(){
						uni.navigateTo({
							url:'../../logins/login/login'
						})
					},2000)
					return false
				}
			
				else {
					global.$http.request({
						url: '/api/home/goodsDetail',
						data: {
							goods_id: b_id,
							category: tabid + 1
						}
					}).then(details => {
						if (details.data.code == 0) {
							console.log('详情',details.data.data);
							if(details.data.data.status==1){
								uni.request({
									url:'http://yzc.taian0538.cn/api/rush_buy/index',
									method: 'POST',
									data:{
										token: uni.getStorageSync('token'),
										goods_id: b_id
									},
									success(response) {
										if (response.data.code == 0) {
											setTimeout(function() {
												uni.navigateTo({
													url: '../../users/confirm_order/confirm_order',
													success: function(res) {
														res.eventChannel.emit('buy', {
															data: {
																shopdetails: details.data.data,
																type:tabid+1,
															}
														})
													}
												})
											}, 2000);
										}
										else if(response.data.code==1){
											uni.showToast({
												title: response.data.msg,
												icon: "none",
												mask: true,
												duration: 2000
											})
										}
									}//
								})
							}
							else{
						
									uni.navigateTo({
										url:'../../indexs/box_details/box_details',
										success: function(res) {
											res.eventChannel.emit('details', {
												data: {
													id: details.data.data.id,
													type:tabid+1,
												}
											})
										}
									})
						
							}
							
							
					

						}
					})
				} 
			},

		}
	}
</script>

<style lang="scss">
	page {
		width: 750rpx;
		// height: 100%;
		font-family: PingFang SC;
		background-color: #111111;
		font-family: PingFang SC-Regular, PingFang SC;

		.main {

			height: 100%;
			width: 750rpx;
			overflow: hidden;

			.wrap {
				padding: 98rpx 32rpx 10rpx 32rpx;
			}

			.tabs {
				background-color: #111111;
				display: flex;
				justify-content: space-between;
				margin-bottom: 60rpx;

				.tabw {
					width: 250rpx;
					height: 140rpx;
					text-align: center;
					padding: 46rpx 36rpx 16rpx 38rpx;
					font-size: 32rpx;
					font-weight: 400;
					color: #FFFFFF;
				}

				.taborder {
					height: 68rpx;
					line-height: 68rpx;
					// background: #08080B;
					border-radius: 16rpx 16rpx 16rpx 16rpx;
					opacity: 1;
					border: 2rpx solid #616C90;
				}

				.tab {
					height: 68rpx;
					line-height: 68rpx;
					// background: #08080B;
					border-radius: 16rpx 16rpx 16rpx 16rpx;
					opacity: 0.2;
				}

			}

			.swipe {

				// position: absolute;
				// left: 8% ;
				.bg {
					width: 580rpx;
					height: 816rpx;
				}
			}

			.top {
				width: 400rpx;
				position: absolute;
				display: flex;
				align-items: center;
				justify-content: space-between;
				top: 40rpx;
				left: 40rpx;

				.title {
					width: 282rpx;
					overflow: hidden;/*超出部分隐藏*/
					white-space: nowrap;/*不换行*/
					text-overflow:ellipsis;/*超出部分文字以...显示*/
					font-size: 36rpx;
					font-weight: bold;
					color: #FFFFFF;
				}

				.num {
					// padding-bottom: 10rpx;
					width: 104rpx;
					text-align: center;
					overflow: hidden;/*超出部分隐藏*/
					white-space: nowrap;/*不换行*/
					text-overflow:ellipsis;/*超出部分文字以...显示*/
					margin-left: 20rpx;
					display: block;
					font-size: 24rpx;
					font-weight: 800;
					height: 44rpx;
					padding: 1rpx 12rpx;
					color: #F9E481;
					border-radius: 18rpx;
					opacity: 1;
					border: 1rpx dashed #F9E481;
				}
			}

			.shop {
				position: absolute;
				top: 98rpx;
				left: 40rpx;
				display: flex;

				image {
					width: 36rpx;
					height: 36rpx;

				}

				text {
					padding-left: 12rpx;
					font-size: 24rpx;
					font-weight: 400;
					color: #FFFFFF;
					opacity: 0.5;
				}
			}

			.moneys {
				text {
					font-size: 28rpx;
					font-weight: 400;
					color: #FFFFFF;
				}

				position: absolute;
				top: 582rpx;
				left: 165rpx;
				width: 106px;
				font-size: 40rpx;
				font-weight: 400;
				color: #FFFFFF;

			}

			.button {
				position: absolute;
				top: 662rpx;
				left: 40rpx;

				image {
					position: absolute;
					top: 0;
					z-index: 0;
				}

				.start {
					width: 300rpx;
					position: absolute;
					top: 28rpx;
					left: 45rpx;
					display: flex;
					align-items: center;
					z-index: 10;

					text {
						font-size: 28rpx;
						font-weight: 400;
						color: #2DEAE6;
					}

					.time {
						padding-left: 16rpx;
					}
				}
			}

			.other {
				height: 200rpx;
				color: #fff;

				view {
					padding: 2rpx 15rpx;
					border-radius: 20rpx;
					border: 1rpx solid #fff;
					opacity: 0.5;
				}
			}

			.other :first-child {
				position: absolute;
				top: 582rpx;
				right: 60rpx;
				z-index: -1;
			}

			.other :last-child {
				position: absolute;
				top: 642rpx;
				right: 75rpx;
				z-index: -1;
			}

			.other2 {
				height: 200rpx;
				color: #fff;

				view {
					padding: 2rpx 15rpx;
					border-radius: 20rpx;
					border: 1rpx solid #fff;
					opacity: 0.0;
				}
			}

			.other2 :first-child {
				position: absolute;
				top: 582rpx;
				right: 60rpx;
				z-index: 10;
			}

			.other2 :last-child {
				position: absolute;
				top: 642rpx;
				right: 75rpx;
				z-index: 10;
			}

			.slide-image {
				position: absolute;
				height: 400rpx;
				width: 400rpx;
				z-index: 5;
				opacity: 0.7;
				z-index: 10;
				top: 158rpx;
				left: 40rpx;
				// margin: 0 20rpx;
			}

			.swipers {

				height: 816rpx;
				position: relative;
				left: 50rpx;
			}

			.active {
				opacity: 1;
				z-index: 10;
				height: 400rpx;
				width: 400rpx;
				top: 158rpx;
				left: 40rpx;
				// transition: all 0.2s ease-in 0s;
			}

			.activeafter {
				opacity: 1;
				z-index: 10;
				height: 316rpx;
				width: 440rpx;
				top: 30%;
				// transition: all 0.2s ease-in 0s;
			}


			.seconds {
				margin: 24rpx 32rpx;
				border-radius: 32rpx 32rpx 32rpx 32rpx;
				opacity: 1;
				border: 2rpx solid #34302F;
				background: #353130;
				position: relative;

				.endtime {
					position: absolute;
					top: 0;
					left: 0;
					padding: 16rpx;
					background: #000000;
					border-radius: 32rpx 0rpx 32rpx 0rpx;
					opacity: 0.5;
					font-size: 24rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #2DEAE6;

					text {
						padding-left: 12rpx;
					}
				}

				.translate {
					border-radius: 32rpx 32rpx 32rpx 32rpx;

					.tr_img {
						width: 686rpx;
						margin: 0 auto;

						image {
							border-radius: 32rpx 32rpx 32rpx 32rpx;
							width: 686rpx;
							height: 686rpx;
						}
					}

					.tt_tit {
						font-size: 32rpx;
						font-weight: bold;
						font-family: PingFang SC-Bold, PingFang SC;
						color: #FFFFFF;
						padding: 24rpx 0 16rpx 32rpx;
					}

					.count {
						padding: 0rpx 32rpx 10rpx 32rpx;

						.coun_name {
							padding: 2rpx 8rpx;
							background: #F4BF57 !important;
							border-radius: 8rpx 0rpx 0rpx 8rpx;
							opacity: 1;
							font-size: 24rpx;
							font-family: PingFang SC-Regular, PingFang SC;
							font-weight: 400;
							color: #333333 !important;

						}

						.coun_num {
							
							padding: 2rpx 8rpx;
							font-size: 24rpx;
							font-family: PingFang SC-Regular, PingFang SC;
							font-weight: 400;
							color: #DBBE7E;
							background: #4C484B;
							border-radius: 8rpx 8rpx 8rpx 8rpx;
							opacity: 1;

						}
					}


					.sec_bot {
						padding: 0rpx 32rpx 32rpx 32rpx;
						display: flex;
						justify-content: space-between;
						align-items: center;

						.market {
							display: flex;
							align-items: center;

							image {
								width: 36rpx;
								height: 36rpx;
								padding-right: 12rpx;
							}

							text {
								font-size: 24rpx;
								font-family: PingFang SC-Regular, PingFang SC;
								font-weight: 400;
								color: #FFFFFF;

							}
						}

						.sec_moneys {
							font-size: 48rpx;
							font-family: PingFang SC-Regular, PingFang SC;
							font-weight: 400;
							color: #FFFFFF;

							text {
								font-size: 32rpx;
								font-family: PingFang SC-Regular, PingFang SC;
								font-weight: 400;
								color: #FFFFFF;
							}
						}
					}

				}
			}
		}
	}
</style>
